<template>
  <s-table
    ref="table"
    size="default"
    :rowKey="(record) => record.data.id"
    :columns="columns"
    :data="loadData"
    :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }">
  </s-table>
</template>

<script>
  import { STable } from '@/components'

  export default {
    components: {
      STable
    },
    data () {
      return {
        columns: [
          {
            title: 'ID',
            dataIndex: 'task_id'
          },
          {
            title: '运行状态',
            dataIndex: 'status'
          },
          {
            title: '持续时间 (秒)',
            dataIndex: 'start_time'
          },
          {
            title: '执行人',
            dataIndex: 'task_creator'
          },
          {
            title: '操作',
            dataIndex: 'task_creator'
          }
        ],
        // 查询条件参数
        queryParam: {},
        // 加载数据方法 必须为 Promise 对象
        // https://ci.ekuaibao.com/api/aslan/workflow/workflowtask/max/50/start/0/pipelines/2-HOSE-UI-web?projectName=ui-auto-test&workflowType=&queryType=&filters=
        loadData: parameter => {
          return this.$http.get('/service', {
            params: Object.assign(parameter, this.queryParam)
          }).then(res => {
            return res.result
          })
        },
        selectedRowKeys: [],
        selectedRows: []
      }
    },
    methods: {
      onSelectChange (selectedRowKeys, selectedRows) {
         this.selectedRowKeys = selectedRowKeys
         this.selectedRows = selectedRows
       }
    }
  }
</script>
